
//
// 110305 - AH - (Fantoft) Created.
// 110306 - AH - (Fantoft Club) Implemented populate.
// 110310a- AH - Implemented scanAndPaint(Set<String>, List<AttributeObject>).
// 110310b- AH - No longer have to pass mine to retrieveInSpareWheel.
// 110617 - AH - (Bybanen *) populate is now final in base class, renamed
//               populate so implements new doPopulate method.
//

package org.soekrat.engine.sparewheel.ontology;

import java.util.List;

import org.soekrat.AttributeObject;
import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.mine.Resource;
import org.soekrat.engine.retrieval.mine.MineRetrievalStrategy;
import org.soekrat.engine.retrieval.mine.MineScan;
import org.soekrat.engine.visitor.Input;
import org.soekrat.engine.visitor.Line;
import org.soekrat.engine.visitor.Lines;
import org.soekrat.engine.wheel.retrieval.RetrievalEvent;

/**
 * <p>
 *   {@link SpareWheelOntology} for a
 *   {@link Mine}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class MineSpareWheelOntology extends SpareWheelOntology 
{
  private final Mine m_mine;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public MineSpareWheelOntology(){ this(null); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param mine Ontology {@code this} access, if {@code null} creates empty.
   */
  public MineSpareWheelOntology(Mine mine)
  {
    m_mine=(mine==null) ? new Mine() : mine;
  }
  
  @Override
  protected void doPopulate(Lines lines)
  {
    if (lines==null)
    {
      throw new NullPointerException("lines");
    }
    
    for (Line line : lines)
    {
      Input input=line.getInput();
      m_mine.populate(input);
    }
  }
  
  /**
   * <p>
   *   Gets ontology {@code this} access.
   * </p>
   * @return {@link Mine}.
   */
  public Mine getMine(){ return m_mine; }

  @Override
  public Input getTokens(List<AttributeObject> paint) 
  {
    if (paint==null)
    {
      throw new NullPointerException("paint");
    }
    
    Input retVal=new Input();
    
    for (AttributeObject curr : paint)
    {
      if (curr instanceof Resource) retVal.add(curr.getName());    
    }
    
    return retVal;
  }
  
  @Override
  public RetrievalEvent scanAndPaint(Input tokens, 
    List<AttributeObject> paint) 
  {
    if (tokens==null)
    {
      throw new NullPointerException("tokens");
    }
    if (paint==null)
    {
      throw new NullPointerException("paint");
    }
    
    //System.out.println("Mine SpareWheelSpoke receive input: "+tokens);
    
    //RetrievalEvent retVal=new RetrievalEvent("SpareWheel : Mine retrieval");
    
    Mine mine=getMine();
    MineScan scan=new MineScan(mine, tokens, true);
    
    //MineRetrievalStrategy.retrieveInSpareWheel(scan, paint, retVal);
    MineRetrievalStrategy.retrieveInSpareWheel(scan, paint, null);
    
    //System.out.println("Mine SpareWheelSpoke painted: "+
    //  AttributeObject.toString(paint));
    
    //return retVal;
    return null;
  }
  
  @Override
  public String toString(){ return m_mine.toString(); }
  
}
